# -*- coding: utf-8 -*-
import chardet
class QSSLoader:
    def __init__(self):
        pass

    @staticmethod
    def read_qss_file(qss_file_name):
        try:
            # 首先尝试使用UTF-8编码读取
            with open(qss_file_name, 'r', encoding='UTF-8') as file:
                return file.read()
        except UnicodeDecodeError:
            try:
                # 如果UTF-8失败，尝试使用GBK编码（常见于中文Windows系统）
                with open(qss_file_name, 'r', encoding='GBK') as file:
                    return file.read()
            except UnicodeDecodeError:
                try:
                    # 如果GBK也失败，尝试自动检测编码
                    with open(qss_file_name, 'rb') as file:
                        raw_data = file.read()
                        result = chardet.detect(raw_data)
                        encoding = result['encoding']

                    # 使用检测到的编码读取文件
                    with open(qss_file_name, 'r', encoding=encoding) as file:
                        return file.read()
                except:
                    # 如果所有方法都失败，返回空字符串
                    print(f"无法读取样式文件: {qss_file_name}")
                    return ""





# class QSSLoader:
#     def __init__(self):
#         pass
#
#     @staticmethod
#     def read_qss_file(qss_file_name):
#         with open(qss_file_name, 'r',  encoding='UTF-8') as file:
#             return file.read()